﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using DotNetUI.Models;

namespace DotNetUI.Controls
{
    /// <summary>
    /// DotNet聊天控件
    /// </summary>
    public class DotNetChatControl : ItemsControl
    {
        /// <summary>
        /// DotNet聊天控件
        /// </summary>
        public DotNetChatControl()
        {
            ClearChatCommand = new DelegateCommand(ClearChatLog, CanClearChatLog);
        }
        private void ClearChatLog(object parameter)
        {
            if (ItemsSource is IList collection)
            {
                collection.Clear();
            }
        }

        private bool CanClearChatLog(object parameter)
        {
            if (ItemsSource != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            ScrollViewer =(ScrollViewer)this.Template.FindName("SCROLLVIEWER",this);

        }
        /// <summary>
        /// 滚动条
        /// </summary>
        public ScrollViewer ScrollViewer { get;private set; }
        static DotNetChatControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DotNetChatControl), new FrameworkPropertyMetadata(typeof(DotNetChatControl)));
        }
        /// <summary>
        /// 显示清空按钮
        /// </summary>
        public bool ShowClearButton { get=>(bool)this.GetValue(ShowClearButtonProperty); set=>SetValue(ShowClearButtonProperty,value); }
        /// <summary>
        /// 显示清空按钮
        /// </summary>
        public static readonly DependencyProperty ShowClearButtonProperty = DependencyProperty.Register(nameof(ShowClearButton), typeof(bool), typeof(DotNetChatControl));
        /// <summary>
        /// 清空聊天记录命令
        /// </summary>
        public ICommand ClearChatCommand { get; }
    }
}
